package com.loongtech.bi.manager.pay;

import com.loongtech.bi.entity.pay.EntityPayUser;
import com.loongtech.bi.entity.pay.EntityPayUserTag;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PayUserManager extends ManagerQueryCacheBase<EntityPayUser> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间，返回这段时间内的单日付费帐号数对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityPayUser> getPayUserByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityPayUser where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}

    /**
     * 根据开始结束时间，返回这段时间内的单日付费帐号数对象
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPayUser> getPayUserByDate2(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPayUser where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday and serverid='0' order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
    }

    /**
     * 根据开始结束时间服务器id，返回这段时间内的单日付费帐号数对象
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPayUserTag> getPayUserByDateByTag(String serverid, Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPayUserTag where serverid=? and startday>=? and endday<=? and startday=endday order by startday ", serverid, Time.getDateStr(dateStart), Time.getDateStr(dateEnd));
    }
	
	/**
	 * 根据开始结束时间，返回所有在这两个时间之间的所有EntityPayUser对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityPayUser> getAllPayUserByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityPayUser where 1=1 and startday=:dayStart and endday=:dayEnd order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}

    /**
     * 根据开始结束时间，返回所有在这两个时间之间的所有EntityPayUser对象
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPayUser> getAllPayUserByDate2(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPayUser where 1=1 and startday=:dayStart and endday=:dayEnd and serverid='0' order by startday ", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
    }

    /**
     * 根据开始结束时间服务器id，返回所有在这两个时间之间的所有EntityPayUser对象
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPayUserTag> getAllPayUserByDateByTag(String serverid, Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPayUserTag where serverid=? and startday=? and endday=? order by startday ", serverid, Time.getDateStr(dateStart), Time.getDateStr(dateEnd));
    }


    /**
	 * 根据开始结束时间，返回所有在这两个时间之间的所有EntityPayUser对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityPayUser> getAllPayUserByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityPayUser where 1=1 and startday=:dayStart and endday=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and addcash_user is not null", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据开始结束时间，求付费人数
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getPayUserByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select startday, addcash_user from EntityPayUser where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and addcash_user is not null", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
	
	/**
	 * 根据开始结束时间，求付费人数对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityPayUser> getTheAllPayUserByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityPayUser where 1=1 and startday>=:dayStart and endday<=:dayEnd and startday=endday and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and addcash_user is not null", "dayStart", Time.getDateStr(dateStart), "dayEnd", Time.getDateStr(dateEnd));
	}
}
